// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  ssr: true,
  devtools: { enabled: true },
  nitro: {
    // 对静态资源压缩
    compressPublicAssets: {
      gzip: true,
      brotli: true,
    },
    output: { dir: "web", serverDir: "web/server", publicDir: "web/public" },
  },
  app: {
    head: {
      title: "魔豆文库",
      // meta: [
      //   { name: 'keywords', content: '魔豆文库,moredoc' },
      //   { name: 'description', content: '魔豆文库，使用Go语言开发的类似百度文库、新浪爱问文库的文库系统解决方案，您不需要会Go语言也能轻松安装部署和使用的文库系统，支持 TXT、PDF、EPUB、MOBI、Office 等格式文档的在线预览与管理，支持云存储、手机登录注册、支付宝微信支付，以及配套的微信小程序。' }
      // ],
      // 全局CSS
      // link: [
      //   {
      //     rel: 'stylesheet',
      //     href: '/static/font-awesome/css/font-awesome.min.css',
      //   },
      //   { rel: 'stylesheet', href: '/static/css/viewer.min.css' },
      //   { rel: 'stylesheet', href: '/static/css/github-markdown-light.css' },
      // ],
      // 全局JS
      // script: [
      //   {
      //     src: '/static/tinymce/tinymce.min.js',
      //   },
      // ],
    },
  },

  // 自动引入
  imports: {
    dirs: [
      "composables",
      "composables/*/index.{ts,js,mjs,mts}",
      "composables/**",
    ],
  },

  modules: ["@element-plus/nuxt", "@pinia/nuxt"],

  routeRules: {
    "/api/**": {
      proxy: `${import.meta.env.SERVER_ADDR}/api/**`,
    },
    "/uploads/**": {
      proxy: `${import.meta.env.SERVER_ADDR}/uploads/**`,
    },
    "/view/**": {
      proxy: `${import.meta.env.SERVER_ADDR}/view/**`,
    },
    "/download/**": {
      proxy: `${import.meta.env.SERVER_ADDR}/download/**`,
    },
  },

  build: {
    // https://github.com/nuxt/nuxt/issues/14553#issuecomment-1397359910
    transpile: [/echarts/, "vue-echarts", "resize-detector"],
  },

  elementPlus: {
    icon: "ElIcon",
    importStyle: "scss",
    themes: ["dark"],
    // 国际化
    locale: "zh-cn",
  },

  css: [
    // 务必要引入element-plus的样式，否则会导致element-plus的组件样式丢失
    "element-plus/theme-chalk/index.css",
    "element-plus/theme-chalk/display.css",
    // 'font-awesome/css/font-awesome.min.css',
    "@/assets/scss/style.scss",
  ],

  vite: {
    css: {
      preprocessorOptions: {
        scss: {
          // https://stackoverflow.com/a/79003101/9101708
          api: "modern-compiler", // or "modern"
        },
      },
    },
  },

  compatibilityDate: "2024-08-15",
});
